package com.bw.patrol.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.constants.RoutePath
import com.bw.common.view.BaseMvvmActivity
import com.bw.patrol.R
import com.bw.patrol.adapter.PatroAdapter
import com.bw.patrol.click.onClick
import com.bw.patrol.databinding.ActivityPatrolBinding
import com.bw.patrol.entity.PatrolEntity
import com.bw.patrol.net.PatrolViewModel


@Route(path = RoutePath.PATH_PATROL)
class PatrolActivity : BaseMvvmActivity<ActivityPatrolBinding,PatrolViewModel>() {

    private lateinit var adapter:PatroAdapter

    private var list:MutableList<PatrolEntity> = mutableListOf()
    override fun initView() {
        binding.topBar.tvTitle.text = "巡逻管理"
        binding.topBar.ivBack.setOnClickListener { finish() }

        adapter= PatroAdapter(list)

        binding.rv.adapter=adapter
        binding.rv.layoutManager=LinearLayoutManager(this)



        adapter.serOnItemClick(object :onClick{
            override fun setOnClick(position: Int) {
                ARouter.getInstance().build(RoutePath.PATH_PATROL_EDIT).navigation()
            }
        })
    }

    override fun initData() {

        vm.patrolSuccess.observe(this){
            list.clear()
            list.addAll(it)
            adapter.notifyDataSetChanged()
        }



    }

    override fun onResume() {
        super.onResume()
        vm.getPatrol()
    }

}